00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #ifndef DE_POLYABT_HPP
00029 #define DE_POLYABT_HPP
00030
00031 #include "deGlobalTypes.hpp"
00032 #include "deArray.hpp"
00033 #include "deSurface.hpp"
00034 #include "deScene.hpp"
00035 #include "deMath.hpp"
00036 #include "deWorld_Helper.hpp"
00037
00038 class IdeVertexBuffer;
00039 class IdeSceneObject;
00040
00041 const int deABT_TexCoords = 4;
00042
00043 class dePolyABT
00044 {
00045 public:
00046
00047 struct ABTVertex
00048 {
00049 deVec3d Position;
00050 deVec3f Normal;
00051 deTexCoord2 TexCoords[deABT_TexCoords];
00052 deARGB Diffuse;
00053 };
00054
00055 struct ABTFace
00056 {
00057 long Indices[3];
00058 long SurfaceID;
00059 };
00060 enum ABTSplitMethod
00061 {
00062 Split_NoMethod,
00063 Split_SuccessiveApprox,
00064 Split_AllVerts,
00065 Split_MultiSample,
00066 Split_Statistical,
00067 Split_Count,
00068 Split_Force32Bit = 0x7fffffff
00069 };
00070
00071 dePolyABT();
00072 ~dePolyABT();
00073
00074
00075 deBoolean SetCurrentSurface(IdeSurface* CurrSurface);
00076
00077
00078 deBoolean AddVertices(ABTVertex* VertexArray, long NumVerts, long & BaseVertexIndex, const deTransformInfo & worldpos);
00079
00080 deBoolean AddTriangleIndices(long* IndexArray, long BaseVertexIndex, long NumIndices);
00081
00082 deBoolean AddSceneObject(IdeSceneObject* pObject);
00083
00084 deBoolean AddIndexedVBuffer(IdeVertexBuffer* VBuffer, long & BaseVertexIndex, const deTransformInfo & worldpos);
00085
00086 deBoolean AddMeshGeometry(IdeMesh* pMesh, const deTransformInfo & worldpos);
00087
00088
00089 deBoolean SetMaxLeafTris(long MaxTris);
00090
00091 deBoolean SetMaxVBufferTris(long MaxTris);
00092
00093
00094
00095
00096
00097
00098
00099
00100 deBoolean SetSplitWeights(deFloat Axis, deFloat Volume, deFloat FaceBalance, deFloat NumSplit);
00101
00102
00103 deBoolean CompileABT();
00104
00105
00106 deBoolean RenderVisibleGeometry(IdeSceneGraph::deSceneTraversal* Params);
00107
00108
00109 void GetVisibleAABB(deAABB& bbox);
00110
00111
00112 deBoolean Serialize(IdeFile * File);
00113 deBoolean DeSerialize(IdeFile * File, u32 DataLength, u32 & AmtRead);
00114 deBoolean DeSerializeLoad();
00115
00116 private:
00117
00118 struct ABTSplit
00119 {
00120 long Axis;
00121 deDouble Percent;
00122 };
00123
00124
00125 struct ABTRenderChunk
00126 {
00127 IdeVertexBuffer* VBuffer;
00128 u32 Surface;
00129 };
00130
00131
00132
00133 struct ABTPartition
00134 {
00135 deAABB BBox;
00136 ABTSplit Split;
00137 deTArray <long> SceneObjectList;
00138 deTArray<ABTFace> Faces;
00139 deTArray<ABTRenderChunk> Renderables;
00140 ABTPartition* Children[2];
00141 ABTPartition* Parent;
00142 deBoolean RenderableBuilt;
00143 };
00144
00145
00146 struct ABTSplitStat
00147 {
00148 ABTSplit Split;
00149 dePlane Plane;
00150 long FrontBackDiff;
00151 long NumOn;
00152 deFloat Score;
00153 };
00154
00155 deTArray<ABTVertex> m_Vertices;
00156 deTArray<ABTFace> m_AllFaces;
00157 deTArray<IdeSurface*> m_Surfaces;
00158 deTArray<IdeSceneObject*> m_SceneObjects;
00159 deAABB m_TotalBBox;
00160 deVec3d m_WorldOffset;
00161 ABTPartition* m_RootPartition;
00162 u32 m_CurrSurfaceIndex;
00163 u32 m_OriginalVertNum;
00164 u32 m_MaxLeafTris;
00165 u32 m_MaxVBTris;
00166 deFloat m_SplitWeights[4];
00167
00168
00169 void DestroyABT();
00170
00171 ABTPartition* CreateABTPartition(ABTPartition * Parent, int ChildNum);
00172 deBoolean DestroyABTPartition(ABTPartition* &pPart);
00173 deBoolean ShrinkPartitionBBoxes(ABTPartition * Parent);
00174 deBoolean ProcessABTPartition(ABTPartition * pPart);
00175 void PickBestSplit(const ABTPartition* pPart, ABTSplitStat & best, ABTSplitMethod method) const;
00176 deBoolean ScorePartitionSplit(const ABTPartition* pPart, ABTSplitStat * pStat, deFloat AxisScores[3]) const;
00177 deBoolean InterpolateCutEdge(ABTVertex * NewVert, long Index1, long Index2, dePlane& SplitPlane);
00178 deBoolean BuildPartitionVBuffer(ABTPartition* pPart);
00179
00180
00181 deBoolean RenderVisibleABTPartitions(IdeSceneGraph::deSceneTraversal* Params, ABTPartition* CurrentPart, deBoolean AllVisible);
00182 deBoolean RenderABTPartition(IdeSceneGraph::deSceneTraversal* Params, ABTPartition* pPart);
00183
00184
00185 deTArray<deIDPair> m_SerialSurfaces, m_SerialObjects;
00186 struct ABTFilePartition_01
00187 {
00188 deAABB BBox;
00189 ABTSplit Split;
00190 u32 childPart[2]; u32 parentPart;
00191 u32 numFaces, faceIndexStart;
00192 u32 numObjects, objectIndexStart;
00193 };
00194 static u32 AppendFilePartition(deTArray<ABTFilePartition_01> & fileparts, const ABTPartition* current, u32 parentIdx, u32 & TotalFaces, u32 & TotalObjects);
00195 ABTPartition* DecomposeFilePartition(const deTArray<ABTFilePartition_01> & fileparts, u32 currentIdx, ABTPartition* parent, const deTArray<u32> objectIndices, const deTArray<ABTFace> faces);
00196 struct readWriteObject_t
00197 {
00198 IdeFile * m_File;
00199 deBoolean m_Write;
00200 u32 m_DataLength, *m_AmtRead;
00201 deBoolean operator()(IdeWorldObject* obj);
00202 };
00203 struct readWriteVertex_t
00204 {
00205 IdeFile * m_File;
00206 deBoolean m_Write;
00207 u32 m_DataLength, *m_AmtRead;
00208 deBoolean operator()(ABTVertex& vert);
00209 };
00210 struct readWriteFace_t
00211 {
00212 IdeFile * m_File;
00213 deBoolean m_Write;
00214 u32 m_DataLength, *m_AmtRead;
00215 deBoolean operator()(ABTFace& face);
00216 };
00217 struct readWritePartition_t
00218 {
00219 IdeFile * m_File;
00220 deBoolean m_Write;
00221 u32 m_DataLength, *m_AmtRead;
00222 deBoolean operator()(ABTFilePartition_01& part);
00223 };
00224 struct grabPartitionData_t
00225 {
00226 deTArray<u32> objects;
00227 deTArray<ABTFace> faces;
00228 deBoolean operator()(ABTFilePartition_01& part);
00229 };
00230 };
00231
00232 #endif // DE_POLYABT_HPP